package com.eascs.web.o2o.web.reward.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.common.util.StringUtil;
import com.eascs.web.o2o.web.reward.dao.BaseDao;
import com.eascs.web.o2o.web.reward.entity.ProvinceSignForm;
import com.eascs.web.o2o.web.reward.service.LoanDayReportService;

@Service
public class LoanDayReportServiceImpl implements LoanDayReportService{

	@Autowired
	BaseDao baseDao;

	@Override
	public PageResult<Object[]> getLoanDayList(ProvinceSignForm entity) {
		SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, entity.getPageSize(), entity.getPageIndex());
		String querySql="select province_name,user_code,user_name,bill_code,"
				+ "round(loan_amount/10000,4) loan_amount,zx_apply_start_date,loan_date,loan_days "
				+ "from dm_evaluate_loan_day_report "
				+ "where /**DATA_PERMISSION(ltd)**/ loan_date>=? and loan_date<=? ";
		sqlPageQuery.setQuerySql(querySql);
		sqlPageQuery.addParam(entity.getDateStart());
		sqlPageQuery.addParam(entity.getDateEnd());
		if(!StringUtil.isEmpty(entity.getProvinceName())) {
			sqlPageQuery.setQuerySql(sqlPageQuery.getQuerySql()+" and province_name=? ");
			sqlPageQuery.addParam(entity.getProvinceName());
		}
		sqlPageQuery.setQuerySql(sqlPageQuery.getQuerySql()+" order by loan_date DESC ");
		return baseDao.findDataWithPage(sqlPageQuery);
	}

}
